#include "stdafx.h"
#include "Game.h"
#include "Input.h"
#include "Timer.h"


CGame::CGame(void)
{
	m_iSpritesLoaded=0;
	m_eGameState = eGameStateMenu;
}


CGame::~CGame(void)
{
}

//
//  FUNCTION: AddSprite
//
//  PURPOSE: adds a sprite into the array that contains all active sprites
//  ( a bit like addChild in Flash)
void
CGame::AddSprite(CSprite * pSprite_)
{
	m_pSprites[m_iSpritesLoaded++]=pSprite_;
}


//
//  FUNCTION: DoFrame()
//
//  PURPOSE: executes one loop of the main game loop.
//

void
CGame::DoFrame()
{
	//get input

	CInput::getInstance()->getInput();
	float dt = CTimer::Instance()->Getdt();

	if (m_eGameState == eGameStateMenu)
	{

		if (CInput::getInstance()->getIfKeyDown(DIK_SPACE))
		{
			m_eGameState = eGameStatePlay;
		}

		m_pMenuSprite->render();

	}

	else if (m_eGameState == eGameStatePlay)
	{
		//update


		for (int i = 0; i < m_iSpritesLoaded; i++)
		{
			m_pSprites[i]->update();
		}


		//render

		for (int i = 0; i < m_iSpritesLoaded; i++)
		{
			m_pSprites[i]->render();
		}

	}
}